$(function() {
	$('.tj').click(function() {
		var data = $(".form").serialize();
		data = toJson(decodeURIComponent(data,true));
		if (!data.mobile.trim()) {
			layer.open({
				content: '手机不能为空!',
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		} else if (!(
				/^(((13[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(15([0-9]{1}))|(18[0-9]{1})|(17+(0|1|2|4|5|3|6|7|8))|(14+(5|6|7|8|9)))+\d{8})$/
				.test(data.mobile))) {
			layer.open({
				content: '手机号格式不正确!',
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		} else if (!data.name.trim()) {
			layer.open({
				content: '姓名不能为空!',
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		} else if (data.name.trim().length > 10) {
			layer.open({
				content: '姓名长度不能超过10位!',
				skin: 'msg',
				time: 2 //2秒后自动关闭
			});
			return false;
		}

		// 登录
		$.ajax({
			type: "post",
			url: "/auth/certification",
			data: data,
			dataType: "json",
			success: function(msg) {
				if (msg.code == 200200) {
					window.location.replace("/goods/list")
				} else {
					layer.open({
						content: msg.message,
						skin: 'msg',
						time: 2 //2秒后自动关闭
					});
				}
			}
		})
		return false;
	})


	//		将字符串转为json
	function toJson(data) {
		data = data.split('&')
		var json = {}
		$.each(data, function(index, value) {
			var arr = value.split('=');
			json[arr[0]] = arr[1]
		});
		return json
	}
})
